import { message } from 'antd';
import request from 'umi-request';

export const ExecuteSQL = async (reportName: string, args: any = null) => {
  await request('/api/services/app/ERPReports/GetByName', {
    method: 'GET',
    params: { name: reportName, rptype: 'SysRpt' },
  }).then(async (response) => {
    if (response) {
      if (response.success) {
        try {
          const result = response.result;
          if (result.reportName) {
            DoExe(result.id, args);
          } else {
            await message.warn('缺失系统报表：' + reportName + '，请在报表管理中新增！');
          }
        } catch (e: any) {
          message.error(e.message);
        }
      }
    }
  });
};
const DoExe = async (id: string, args: any) => {
  await request('/api/services/app/ERPReports/ExecuteSQL', {
    method: 'POST',
    data: { id, args },
  }).then((response) => {
    if (response) {
      if (response.success) {
        console.log(response.result);
        message.success('执行成功');
      }
    }
  });
};
